using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace stsdev {
  public class ActivityClassesBuilder {

    

    public static void CreateActivityClasses(string sActivityName) {
        string ActivitySourceFilePath = sActivityName + ".cs";
        string ActivityDesignerSourceFilePath = sActivityName + "_Designer.cs";
        string ActivityDesignerThemeSourceFilePath = sActivityName + "_DesignerTheme.cs";
        string ActivityValidatorSourceFilePath = sActivityName + "Validator.cs";
        string ActivityToolBoxItemSourceFilePath = sActivityName + "_ToolBoxItem.cs";
        string ActivityVSDesignerSourceFilePath = sActivityName + ".Designer.cs";

        #region ActivitySourceFilePath
        FileStream fs = File.Create(ActivitySourceFilePath);
        StreamWriter writer = new StreamWriter(fs);
        string content = WFActivitySolutionProvider.Properties.Resources.Activity_cs;
        content = content.Replace("@SolutionName", SolutionBuilder.SolutionName);
        content = content.Replace("@ClassName", sActivityName);
        writer.Write(content);
        writer.Dispose();
        fs.Dispose();
        ProjectFileBuilder.AddSourceFile(ActivitySourceFilePath,SourceFileTypeEnum.Compile);
        #endregion

        #region ActivityDesignerSourceFilePath
        fs = File.Create(ActivityDesignerSourceFilePath);
        writer = new StreamWriter(fs);
        content = WFActivitySolutionProvider.Properties.Resources.Activity_DesignerClass_cs;
        content = content.Replace("@SolutionName", SolutionBuilder.SolutionName);
        content = content.Replace("@ClassName", sActivityName);
        writer.Write(content);
        writer.Dispose();
        fs.Dispose();
        ProjectFileBuilder.AddSourceFile(ActivityDesignerSourceFilePath, SourceFileTypeEnum.Compile);
        #endregion

        #region ActivityDesignerThemeSourceFilePath
        fs = File.Create(ActivityDesignerThemeSourceFilePath);
        writer = new StreamWriter(fs);
        content = WFActivitySolutionProvider.Properties.Resources.Activity_DesignerTheme_cs;
        content = content.Replace("@SolutionName", SolutionBuilder.SolutionName);
        content = content.Replace("@ClassName", sActivityName);
        writer.Write(content);
        writer.Dispose();
        fs.Dispose();
        ProjectFileBuilder.AddSourceFile(ActivityDesignerThemeSourceFilePath, SourceFileTypeEnum.Compile);
        #endregion

        #region ActivityValidatorSourceFilePath
        fs = File.Create(ActivityValidatorSourceFilePath);
        writer = new StreamWriter(fs);
        content = WFActivitySolutionProvider.Properties.Resources.Activity_Validator_cs;
        content = content.Replace("@SolutionName", SolutionBuilder.SolutionName);
        content = content.Replace("@ClassName", sActivityName);
        writer.Write(content);
        writer.Dispose();
        fs.Dispose();
        ProjectFileBuilder.AddSourceFile(ActivityValidatorSourceFilePath, SourceFileTypeEnum.Compile);
        #endregion

        #region ActivityToolBoxItemSourceFilePath
        fs = File.Create(ActivityToolBoxItemSourceFilePath);
        writer = new StreamWriter(fs);
        content = WFActivitySolutionProvider.Properties.Resources.Activity_ToolboxItem_cs;
        content = content.Replace("@SolutionName", SolutionBuilder.SolutionName);
        content = content.Replace("@ClassName", sActivityName);
        writer.Write(content);
        writer.Dispose();
        fs.Dispose();
        ProjectFileBuilder.AddSourceFile(ActivityToolBoxItemSourceFilePath, SourceFileTypeEnum.Compile);
        #endregion

        #region ActivityVSDesignerSourceFilePath
        fs = File.Create(ActivityVSDesignerSourceFilePath);
        writer = new StreamWriter(fs);
        content = WFActivitySolutionProvider.Properties.Resources.Activity_VSDesigner_cs;
        content = content.Replace("@SolutionName", SolutionBuilder.SolutionName);
        content = content.Replace("@ClassName", sActivityName);
        writer.Write(content);
        writer.Dispose();
        fs.Dispose();
        ProjectFileBuilder.AddSourceFile(ActivityVSDesignerSourceFilePath, SourceFileTypeEnum.Compile);
        #endregion

      
    }

    public static void CreateActivityFeature() {
      //FeatureBuilder.CreateElementManifest("WebParts.xml", ElementsWriterCallback);      
      //FeatureBuilder.Create(SolutionBuilder.SolutionName, FeatureScopeEnum.Site, false);      
    }

    private static void ElementsWriterCallback(XmlWriter writer) {
      //writer.WriteStartElement("Module");
      //writer.WriteAttributeString("Name", SolutionBuilder.SolutionName);
      //writer.WriteAttributeString("List", "113");
      //writer.WriteAttributeString("Url", "_catalogs/wp");
      //writer.WriteAttributeString("Path", "WebParts");
      //writer.WriteAttributeString("RootWebOnly", "True");

      //foreach (string WebPartName in WebPartNames) {
      //  writer.WriteStartElement("File");
      //  writer.WriteAttributeString("Url", WebPartName + ".webpart");
      //  writer.WriteAttributeString("Type", "GhostableInLibrary");
      //  writer.WriteStartElement("Property");
      //  writer.WriteAttributeString("Name", "Group");
      //  writer.WriteAttributeString("Value", SolutionBuilder.SolutionName);
      //  writer.WriteEndElement(); // </Property>
      //  writer.WriteEndElement(); // </File>
      //}      
      
      //writer.WriteEndElement(); // </Module>
    }
  }
}

